package app.controller.http;

import app.vo.Card;
import app.vo.User;
import org.ricks.common.json.JSONArray;
import org.ricks.common.json.JSONUtil;
import org.ricks.db.EntityMgr;
import org.ricks.log.Logger;
import org.ricks.net.http.Controller;
import org.ricks.net.http.RequestMapping;
import org.ricks.utils.RandomUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author chenwei
 * @Title:
 * @Package
 * @Description:
 * @date 2022/12/511:18
 */
@Controller("ricks")
public class HttpController {

    @RequestMapping(value = "test")
    public String test() {
        Logger.info("dedeededed" );
        return "demon is god  进入，，，，，    凯子是哈皮，， 小汪  小汪  小汪";
    }

    @RequestMapping(value = "test1")
    public User test1() {
        User user = new User();
        user.setAge(18);
        user.setRoleName("demon-"+ System.nanoTime());
        user.setGold(9999);
        user.setSendGift(1);
        user.setGreetings("哈哈哈11111111111111111111");
        user.setLv(99);
        user.setFinalCityId(1000);
        user.setRoleId(5336600786298418384l);
        user.setId(3533336842617225216L);
        user.update();


        User user1 = new User();
        user1.setAge(18);
        user1.setRoleName("demon-"+ System.nanoTime());
        user1.setGold(9999);
        user1.setSendGift(1);
        user1.setGreetings("哈哈哈222222222222222222222222");
        user1.setLv(99);
        user1.setFinalCityId(1000);
        user1.setRoleId(4369497559225200411l);
        user1.setId(3533337058539995136L);
        user1.update();


//        User user3 = new User();
//        user3.setAge(18);
//        user3.setRoleName("demon-"+ System.nanoTime());
//        user3.setGold(9999);
//        user3.setSendGift(1);
//        user3.setGreetings("哈哈哈222222222222222222222222");
//        user3.setLv(99);
//        user3.setFinalCityId(1000);
//        user3.setRoleId(RandomUtil.randomLong());
//        Map<Integer,String> map = new HashMap<>();
//        map.put(1,"demon");
//        map.put(2,"is");
//        map.put(3,"god");
//        user3.setResource(map);
        List<User> addUsers = new ArrayList<>();
        for (int i = 0; i < 3000; i++) {
            User user3 = new User();
            user3.setAge(18);
            user3.setRoleName("demon-"+ System.nanoTime());
            user3.setGold(9999);
            user3.setSendGift(1);
            user3.setGreetings("哈哈哈222222222222222222222222");
            user3.setLv(99);
            user3.setFinalCityId(1000);
            user3.setRoleId(RandomUtil.randomLong());
            Map<Integer,String> map = new HashMap<>();
            map.put(1,"demon");
            map.put(2,"is");
            map.put(3,"god");
            user3.setResource(map);
            addUsers.add(user3);

        }
        EntityMgr.save(User.class,addUsers);
//        user3.setGreetings("开始更新，，，，，，");
//
//        List<Card> friends = new ArrayList<>();
//        Card card1 = new Card(1,"展示",1);
//        Card card2 = new Card(2,"法师",1);
//        List<String> friendStr = new ArrayList<>();
//        friendStr.add("汪婷");
//        friendStr.add("晓涵");
//        friends.add(card1);
//        friends.add(card2);
//        Map<Integer,Card> map1 = new HashMap<>();
//        map1.put(1,card1);
//        map1.put(2, card2);
//        user3.setResource1(map1);
//        user3.setFriends(friends);
//        user3.setFriendStr(friendStr);
//        user3.setBytes("hello fuck you".getBytes());
//        user3.update();
        User user4 = new User();
        user4.setId(3550779548532473856L);
        user4 = user4.get();
//        String stt = new String(user4.getBytes());
//        System.err.println(stt);
        user1.save();
        user1.delete();
        user1.update();

        return user4;
    }

    @RequestMapping(value = "test2")
    public User test2() {
        User user = new User();
        user.setAge(18);
        user.setRoleName("demon");
        user.setGold(9999);
        user.setSendGift(1);
        user.setGreetings("哈哈哈111");
        user.setLv(99);
        user.setFinalCityId(1000);
        user.setId(3533336842617225216L);
        List<User> users = EntityMgr.list(user,"age");
        if(user != null) {
            users.forEach(u -> System.err.println(u.getId()));

            System.err.println(" size : " + users.size());
        }
        return user;
    }

    @RequestMapping(value = "test3")
    public void test3() {
        JSONArray jsonArray = JSONUtil.parseArray("[{\"cardName\":\"法师\",\"count\":1,\"cardId\":2}]");
        List list = jsonArray.toList(Card.class);
        System.err.println("......");
    }
}
